package edu.qust.y22.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import edu.qust.y22.bean.Adticket;
import edu.qust.y22.constant.ErrorEnum;
import edu.qust.y22.constant.Message;
import edu.qust.y22.service.AdticketService;

@RestController
@RequestMapping("/bac/adticket")
public class AdticketController {
	
	@Autowired
	private AdticketService adticketService;
	
	@RequestMapping("selectAdticket")
	public Message selectAdticket(@RequestBody Adticket adticket) {
		if("".equals(adticket.getAdminUserName())) {
			return Message.createFailureMessage(ErrorEnum.UnkonwError);
		}
		List<Adticket> adtickets = this.adticketService.selectAdticketByName(adticket.getAdminUserName());
		return Message.createSuccessMessage(adtickets);
	}
	@RequestMapping("deleteAdticket")
	public Message deleteAdticket(@RequestBody Adticket adticket) {
		boolean success = this.adticketService.deleteAdticketById(adticket.getId());
		if(success==false) {
			return Message.createFailureMessage(ErrorEnum.UnkonwError);
		}
		return Message.createSuccessMessage();
	}
	@RequestMapping("insertAdticket")
	public Message insertAdticket(@RequestBody Adticket adticket) {
		boolean success = this.adticketService.inertAdticket(adticket);
		if(success!=true) {
			return Message.createFailureMessage(ErrorEnum.UnkonwError);
		}
		return Message.createSuccessMessage();
	}
}
